package Class014;

import java.util.Stack;

public class MinStack {
    public static void main(String[] args) {

    }

    public static class MyMinStack {
        public Stack<Integer> minStack;
        public Stack<Integer> ordinaryStack;
        public MyMinStack() {
            minStack = new Stack<>();
            ordinaryStack = new Stack<>();
        }

        public void push(int val) {
            ordinaryStack.push(val);
            if(minStack.isEmpty() || minStack.peek() >= val) {
                minStack.push(val);
            }else {
                minStack.push(minStack.peek());
            }
        }
        public int pop() {
            minStack.pop();
            return ordinaryStack.pop();
        }
        public int peek() {
            return ordinaryStack.peek();
        }
        public int getMin() {
            return minStack.peek();
        }
    }
}
